package nix.anim.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import nix.anim.common.pojo.LogAnnotation;
import nix.anim.common.pojo.NixResult;
import nix.anim.pojo.Role;
import nix.anim.service.RoleService;

/**
 * 角色管理Controller
 */
@Controller
public class RoleController {

	@Autowired
	private RoleService roleService;
	
	@RequestMapping(value="/api/role/list", method=RequestMethod.GET)
	@ResponseBody
	public NixResult getRoleList(Integer page, Integer rows) {	
		// 调用服务
		NixResult result = roleService.getRoleList(page, rows);
		return result;
	}
	
	@RequestMapping(value="/api/role/save", method=RequestMethod.POST)
	@ResponseBody
	@LogAnnotation(action="新增/修改", object="角色")
	public NixResult saveRole(Role role) {
		NixResult result = new NixResult();
		if (role.getId() == null) {
			// Add
			result = roleService.addRole(role);
		} else {
			// Update
			result = roleService.updateRole(role);
		}
		return result;
	}
	
	@RequestMapping(value="/api/role/right/{id}", method=RequestMethod.GET)
	@ResponseBody
	public NixResult getRoleRightIds(@PathVariable Integer id) {
		// 调用服务
		NixResult result = roleService.getRoleRightIds(id);
		return result;
	}
	
	@RequestMapping(value="/api/role/setright", method=RequestMethod.POST)
	@ResponseBody
	@LogAnnotation(action="指定权限", object="角色权限")
	public NixResult setRoleRight(Integer roleId, String rightIds) {
		// 调用服务
		NixResult result = roleService.setRoleRight(roleId, rightIds);
		return result;
	}
}
